/*     */ package com.chw.common;
/*     */ 
/*     */ import com.chw.utils.Md5EncryptUtil;
/*     */ import com.google.gson.Gson;
/*     */ import java.io.PrintStream;
/*     */ import java.util.Date;
/*     */ import org.apache.commons.codec.binary.Base64;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.apache.commons.lang3.time.DateUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class SecureInfo
/*     */ {
/*  18 */   private static final Logger log = Logger.getLogger(SecureInfo.class);
/*     */   private static final int TIMEOUT_DAY_AMOUNT = 90;
/*     */   private String userId;
/*     */   private Date expiration;
/*     */ 
/*     */   public SecureInfo(String userId)
/*     */   {
/*  27 */     this(userId, DateUtils.addDays(new Date(), 90));
/*     */   }
/*     */ 
/*     */   public SecureInfo(String userId, Date expiration) {
/*  31 */     this.userId = userId;
/*  32 */     this.expiration = expiration;
/*     */   }
/*     */ 
/*     */   public String getUserId() {
/*  36 */     return this.userId;
/*     */   }
/*     */ 
/*     */   public void setUserId(String userId)
/*     */   {
/*  41 */     this.userId = userId;
/*     */   }
/*     */ 
/*     */   public Date getExpiration() {
/*  45 */     return this.expiration;
/*     */   }
/*     */ 
/*     */   public void setExpiration(Date expiration) {
/*  49 */     this.expiration = expiration;
/*     */   }
/*     */ 
/*     */   public String encode()
/*     */   {
/*  54 */     if ((StringUtils.isEmpty(this.userId)) || (this.expiration == null))
/*     */     {
/*  56 */       return null;
/*     */     }
/*     */ 
/*  59 */     String secureToken = Base64.encodeBase64String(new Gson().toJson(this).getBytes());
/*     */ 
/*  61 */     return secureToken + "." + Md5EncryptUtil.encode(secureToken, true);
/*     */   }
/*     */ 
/*     */   public static SecureInfo decode(String secureToken)
/*     */   {
/*  67 */     if (StringUtils.isEmpty(secureToken)) {
/*  68 */       return null;
/*     */     }
/*     */ 
/*  71 */     String[] secures = secureToken.split("\\.");
/*  72 */     if (secures.length != 2) {
/*  73 */       return null;
/*     */     }
/*     */ 
/*  76 */     if (!StringUtils.equals(Md5EncryptUtil.encode(secures[0], true), secures[1])) {
/*  77 */       return null;
/*     */     }
/*     */ 
/*  80 */     String info = new String(Base64.decodeBase64(secures[0]));
/*     */ 
/*  82 */     return (SecureInfo)new Gson().fromJson(info, SecureInfo.class);
/*     */   }
/*     */ 
/*     */   public static void main(String[] args)
/*     */   {
/*  87 */     System.out.println(new SecureInfo("6714aaff60f1465e8a899c38260fa910").encode());
/*     */ 
/*  89 */     System.out.println("id:" + decode("eyJ1c2VySWQiOiI2NzE0YWFmZjYwZjE0NjVlOGE4OTljMzgyNjBmYTkxMCIsImV4cGlyYXRpb24iOiJNYXkgMTAsIDIwMTcgMjozMjoxMCBQTSJ9.0edf6bc91af54d6bf6bc66c9e6a9712c").getUserId());
/*     */ 
/*  91 */     String mobile = "";
/*     */ 
/*  93 */     String from = "1";
/*     */ 
/*  95 */     String ver = "1.0";
/*     */ 
/*  97 */     String tm = "1486602655943";
/*     */ 
/*  99 */     String preSign = mobile + from + ver + tm;
/*     */ 
/* 101 */     System.out.println(preSign);
/*     */ 
/* 103 */     System.out.println(Md5EncryptUtil.encode(preSign, true));
/*     */   }
/*     */ }

/* Location:           H:\2017 4-21\chw-common\common\
 * Qualified Name:     com.chw.common.SecureInfo
 * JD-Core Version:    0.5.4
 */